/**
 * Created by Administrator on 2015/12/29.
 */
angular.module('ywkh.controller',[])
  .controller('ywkhCtrl',['$scope','ywkhService','ddcxService','$timeout','$ionicPopup','$state','$ionicPopover','$cordovaBarcodeScanner','$localstorage','$state','$ionicLoading',function($scope,ywkhService,ddcxService,$timeout,$ionicPopup,$state,$ionicPopover,$cordovaBarcodeScanner,$localstorage,$state,$ionicLoading) {

    $scope.params = {};
    $scope.$on('$ionicView.enter', function (event, data) {
      $scope.params = ywkhService.getParams();

        if (data.stateId == 'ywkh'){
          $scope.reset();

          if($localstorage.get("LOG_FLAG")=="1"){
            ywkhService.insertLog("移网开户").then(function(data){
              //console.log("插入日志"+angular.toJson(data));
            },function(error){
              //console.log("插入日志失败，请联系管理员");
            });
          }

        }
        if (data.stateId == 'ywkh/step2') {
        $scope.selecttc = '2G';//默认是选中2G
        $scope.params.val_tclx = "2G";//默认是选中2G
        $scope.xuanzf = 1;//是否隐藏套餐资费的div 等于1时隐藏
        $scope.params.step2=0;
        $scope.step2select=null;
        var param = {
          "prodSysType": "2G",
         // "netTypeCode": $scope.params.Product.NET_TYPE_CODE
        }
        ywkhService.getProductList(param).then(function (success) {
          $scope.params.ProductList = angular.fromJson(success.data);
        }, function (error) {
          //console.log(error);
        });
      };
      if (data.stateId == 'ywkh/step3') {
        $scope.params.queryNum="";
        $scope.params.PhoneNumList=[];
        $scope.params.step3=0;
        $scope.params.step3page=1;
        $scope.params.val_kplb = '白卡';
        //step3切换tab页
        $scope.selectTab('tab-1')
        //$scope.doNumRefresh();//这里不要做刷新，只要ng-if的值为true，就会默认调用loadmore的方法
      }
      if(data.stateId=='ywkh/step3_2'){
        $scope.params.DeveloperList=[];
        $scope.step3_2page=1;
        $scope.params.queryfzr="";
        $scope.params.step3_2=0;
      }
      if(data.stateId=='ywkh/step4'){
       // console.log($scope.params.PhoneNumList);
      }

    });
    //==========================================step1========================================================

    /*移网开户step1身份证验证*/
    $scope.ReadIdCard = function () {
      var mac = $localstorage.get("mac");
      if (mac) {
        var param = {"mac": mac};
        ywkhService.ReadIdCard(param);
      } else {
        var alertPopup=$ionicPopup.alert({
        title:'读取失败',
        template:"蓝牙未设置，请先去用户中心设置蓝牙！",
        okText: '确定', // String (默认: 'OK')。OK按钮的文字。
        okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
      });
      }
    };

    /*   $scope.vaContect=function()
     {
     var reg=/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i
     if(reg.test($scope.params.ConTel)){
     $scope.params.step12=1;
     }else{
     $scope.params.step12=0;
     }
     }*/
    //step1按钮重置功能
    $scope.reset = function () {
      $scope.params.ConTel = '';
      $scope.params.IdCard = {};
      $scope.params.step1 = 0;
    }
    //========================================step2===========================================================


    //step2选择套餐按钮控制
    $scope.checktc = function (value) {
      $scope.params.val_tclx = value;
      $scope.params.step2 = 0;
      $scope.step2select = null;//每次点击套餐类别置空用户选择的套餐索引
      $scope.selectzf = null;//每次点击套餐类别置空用户选择的套餐资费
      $scope.xuanzf = 1;//每次点击套餐类别隐藏首月资费
      $scope.selecttc = value;
      var param = {
        "prodSysType": value
      }
      ywkhService.getProductList(param).then(function (success) {
        $scope.params.ProductList= angular.fromJson(success.data);
      }, function (error) {
        //console.log(error);
      });
    };
    //step2选中套餐时改变选中item的颜色
    $scope.selecttcxq = function (index, item) {
      $scope.params.Product = item;
      $scope.step2select = index;
      $scope.selectzf = null;
      if ($scope.params.val_tclx == "2G") {
        $scope.xuanzf = 0;//等于1时套餐资费隐藏
        $scope.params.step2 = 0;//params.step2==1时下一步按钮可用
      } else {
        $scope.xuanzf = 0;//等于0时套餐资费显示（必选）
        $scope.params.step2 = 0;//params.step2==0时下一步按钮不可用
      }

    };

    //step2选择套餐资费
    $scope.checkzf = function (value) {
      $scope.params.val_tczf = value;
      $scope.selectzf = value;
      $scope.params.step2 = 1;
    };

    //step2选完套餐后验证是否是黑名单
    $scope.checkperson = function () {
      //if (sysCode()=="CBS") {
        var param = {
          "psptId": $scope.params.IdCard.cardNo,
          "sysCode": sysCode()
        }
        //console.log(param);
        ywkhService.Authenticate(param).then(
          function (success) {
            if("CBS"==sysCode()) {
              $scope.params.CustList = success.data;
            }
            if (success.respCode!= "0") {
              $scope.show(success.respDesc);
            } else {
              $state.go("ywkh/step3");
            }
          }, function (error) {
          });
      //}
    }
    /*长按弹出套餐详情*/
    $ionicPopover.fromTemplateUrl('tcxq.html', {
      scope: $scope
    }).then(function (popover) {
      $scope.popover3 = popover;
    });
    $scope.opentcxq = function ($event,index,item) {
      if(!item){

      }else{
        $scope.params.Product = item;
      }
      $scope.step2select = index;
      $scope.popover3.show($event);
    };
    $scope.closetcxq = function () {
      $scope.popover3.hide();
    };
//ionicLoading step2用户身份校验不通过弹出框
     $scope.show=function(error){
     $scope.params.errorReason=error;
     $ionicLoading.show({
     templateUrl:'check.html',
     scope:$scope
     });
     };
    $scope.hideLoading = function () {
      $ionicLoading.hide();
      $state.go("maincontent");
    };
//===========================================step3==============================================================


    //切换tab页
    $scope.selectTab = function (_tab) {
      $scope.showTab = _tab;
      $scope.params.BarSimCard.text=''
      $scope.numselect=null;
      if (_tab == "tab-1") {
        $scope.params.val_kplb = '白卡';
      } else {
        $scope.params.val_kplb = '成卡';
      }
      $scope.params.step3=0;
    };
    /**************白卡*********************/
      //选中号码时改变选中item的颜色，同时给params传递选中的值
    $scope.selectNum = function (index, item) {
      $scope.numselect = index;
      $scope.params.PhoneNum=item;
      $scope.validSerialNumber();
    };
    $scope.doNumRefresh = function () {
      $scope.params.step3=0;
      $scope.params.step3page=1;

      if(sysCode()=="CBS"){
        var param = {
          "ycType":"",
          "serialNumber":"",
          "queryTag":"1",
          "lhType":"1",
          "sysCode":sysCode(),//系统编码 CBS 、BSS 、ESS ，必填
          "netTypeCode":50, // 业务类型，必选
          "hwxh":"",// 是否号尾选号，可选
          "snPostfix":$scope.params.queryNum,// 号码后缀，可选
        };
      }else{
        var param = {
          "sysCode": sysCode(),
          "currPage":"1",
          "netTypeCode": $scope.params.Product.NET_TYPE_CODE,
          "serialNumber":$scope.params.queryNum,
          "snPrefix":$scope.params.queryNum
        };
      }
      ywkhService.querySerialNumberList(param).then(
        function(success){
          //console.log(success);
          $scope.params.PhoneNumList=angular.fromJson(success.data);
          $scope.params.step3page=2;//因为每次刷新后页面会重置为1，然后再去调用上拉加载的方法，才会拼接第二页的数据，不然就会拼接第一页数据，重复显示。
        },function(error){
          //console.log(error);
        }).finally(function(){
          $scope.$broadcast('scroll.refreshComplete');
        });
      };

      //要让scroller知道我们已经加载完了新项目，可以隐藏加载指示。为了达到这个目的，我们要广播scroll.refreshComplete事件

    /**
     * 上拉加载
     */
    $scope.doNumLoadMore = function () {
      if(sysCode()=="CBS"){
        var param = {
          "sysCode": sysCode(),
          "currPage": $scope.params.step3page++,
          "netTypeCode":"50",
          "serialNumber":$scope.params.queryNum,
        };
      }else {
        var param = {
          "sysCode": sysCode(),
          "currPage": $scope.params.step3page++,
          "netTypeCode": $scope.params.Product.NET_TYPE_CODE,
          "serialNumber": $scope.params.queryNum,
        };
      }
      /*var param = {
        "sysCode": sysCode(),
        "currPage": $scope.params.step3page++,
        "serialNumber":$scope.params.queryNum
      };*/
      ywkhService.querySerialNumberList(param).then(
        function(success){
          //console.log(success);
          $scope.params.PhoneNumList=$scope.params.PhoneNumList.concat(angular.fromJson(success.data));
          //console.log($scope.params.PhoneNumList.length);
          if(!success.data||$scope.params.PhoneNumList.length==1){
            $scope.params.NummoreData=false;
          }else{
            $scope.params.NummoreData=true;
          }
        },function(error){
          //console.log(error);
        }).finally(function(){
          $scope.$broadcast('scroll.infiniteScrollComplete');
        });
    };
    /**************成卡*********************/
   //用蓝牙读卡器读取手机号
    $scope.readSimCard=function(){
      var mac=$localstorage.get("mac");
      if(mac){
        var param={"mac":mac};
        ywkhService.readSimCard(param);
      }
      else{
        var alertPopup=$ionicPopup.alert({
          title:'读取失败',
          template:"蓝牙未设置，请先去用户中心设置蓝牙！",
          okText: '确定', // String (默认: 'OK')。OK按钮的文字。
          okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
        });
      }
      $scope.params.step3=1;
    };
    //根据条形码扫描sim卡
    $scope.saomiao=function(){
      $cordovaBarcodeScanner
        .scan()
        .then(function (result) {
          $scope.params.MobilePhone='';
          $scope.params.BarSimCard=angular.fromJson(result);
          $scope.params.QueryUserBySimParams.QryType= "1";
          var text=$scope.params.BarSimCard.text.substring(0,$scope.params.BarSimCard.text.length-1);
          $scope.params.BarSimCard.text=text;
          $scope.params.QueryUserBySimParams.QryCode=$scope.params.BarSimCard.text;
          queryUserBySim($scope.params.QueryUserBySimParams);
          $scope.params.step3=1;
        },
        function (error) {
          $scope.params.step3=0;
        });

    };
    $scope.ReadIccid=function(){
      $scope.params.BlueSimCard={};
      var mac=$localstorage.get("mac");
      if(mac) {
        var param={"mac":mac};
        ywkhService.ReadIccid(param,function(success){
          $scope.params.BlueSimCard=angular.fromJson(success);
          if($scope.params.BlueSimCard.retCode=="0"){
           // $scope.params.BarSimCard.text = $scope.params.BlueSimCard.ICCID;
            $scope.params.QueryUserBySimParams.QryType = "1";
            //$scope.params.QueryUserBySimParams.QryCode = $scope.params.BarSimCard.text;
            $scope.params.QueryUserBySimParams.QryCode=$scope.params.BlueSimCard.ICCID;
            queryUserBySim($scope.params.QueryUserBySimParams);
          }else{
            var alertPopup=$ionicPopup.alert({
              title:'读取失败',
              template:"请重新尝试读取",
              okText: '确定', // String (默认: 'OK')。OK按钮的文字。
              okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
            });
          }
        },function(error){
          var alertPopup=$ionicPopup.alert({
            title:'读取失败',
            template:"请重新读取，确认已经插卡",
            okText: '确定', // String (默认: 'OK')。OK按钮的文字。
            okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
          });
        });

      }else{
        var alertPopup=$ionicPopup.alert({
          title:'读取失败',
          template:"请先去用户中心连接蓝牙！",
          okText: '确定', // String (默认: 'OK')。OK按钮的文字。
          okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
        });
      }
    }
    //手机号码输入框 离开焦点
    $scope.validMobilePhone=function(isValid)
    {
     // console.log(isValid);
      //判断手机号的校验合法的情况下
      if(isValid)
      {
        //先做号码预占然后手机号和iccid互查操作
        $scope.params.PhoneNum.serialNumber=$scope.params.MobilePhone;

        var param={
          "sysCode":sysCode(),
          "resourcesType":"02",
          "resourcesCode": $scope.params.PhoneNum.serialNumber
        }
        ywkhService.validSerialNumber2G(param).then(function(success){
          if(success.respCode!="0"){
            var alertPopup=$ionicPopup.alert({
              title:'号码预占失败',
              template:""/*angular.toJson(success)*/,
              okText: '确定', // String (默认: 'OK')。OK按钮的文字。
              okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
            });
          }else{
            $scope.params.BarSimCard.text='';
            $scope.params.searchUserInfoByPhone.mobilePhone=$scope.params.MobilePhone;
            validMobilePhone( $scope.params.searchUserInfoByPhone);
          }
        },function(error){
        });






      }
      else//不合法
      {
      }
    };
    //调用手机号校验的接口
    function validMobilePhone(params)
    {
          $scope.params.QueryUserBySimParams.QryType= "2";
          $scope.params.QueryUserBySimParams.QryCode= $scope.params.MobilePhone;
          queryUserBySim($scope.params.QueryUserBySimParams);
    };
    //SIM卡号和手机号互查
    function queryUserBySim(params)
    {
      //调用通过手机号查询iccid的接口
      ywkhService.queryUserBySim(params).then(
        function(data){
          if(data.respCode=="-1")//查询SIM卡号失败
          {
            var alertPopup=$ionicPopup.alert({
              title:'查询SIM卡号失败',
              template:data.respDesc,
              okText: '确定', // String (默认: 'OK')。OK按钮的文字。
              okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
            });
          }
          else
          {
            if($scope.params.QueryUserBySimParams.QryType=="1") //根据SIM卡号查号码
            {
              //console.log("我给手机赋值");
              $scope.params.MobilePhone=data.data.UserNum;
              $scope.params.step3=1;
            }
            else //根据号码查询SIM卡号
            {
              //console.log("我给SIM卡号赋值");
              $scope.params.BarSimCard.text=data.data.UserNum;
              $scope.params.step3=1;
            }
          }
        },function(error){

        });
    }


//=======================================step3_1================================================
    //选择活动的级联
    function changeHuoDong(value) {
      ywkhService.changeHuoDong(value);
    };

    /*step3_1自定义数字 浮动框1*/
    $ionicPopover.fromTemplateUrl('hdlx.html', {
      scope: $scope
    }).then(function (popover) {
      $scope.popover1 = popover;
    });
    $scope.openhdlx = function ($event) {
      $scope.popover1.show($event);
    };
    $scope.closehdlx = function (item) {
      $scope.params.val_hdlx = item.htname;
      changeHuoDong(item.htid);
      $scope.popover1.hide();
    };
//=======================================step3_2================================================
    //号码预占用
    $scope.validSerialNumber=function(){
      if(sysCode()=="CBS"){
      var param={
        "sysCode":sysCode(),//系统编码 CBS 、BSS 、ESS ，必填
        "occupiedFlag":"1",
        "resourcesCode":$scope.params.PhoneNum.serialNumber,
        "serialNumber": $scope.params.PhoneNum.serialNumber, // 号码，必选
        "netTypeCode":"50"
      }
        ywkhService.validSerialNumber4G(param).then(function(success){
          if(success.respCode!="0"){
            var alertPopup=$ionicPopup.alert({
              title:'号码预占失败',
              template:""/*angular.toJson(success)*/,
              okText: '确定', // String (默认: 'OK')。OK按钮的文字。
              okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
            });
          }else{
            $scope.params.step3=1;
          }
        },function(error){
        });
      }else{
        var param={
          "sysCode":sysCode(),
          "resourcesType":"02",
          "resourcesCode": $scope.params.PhoneNum.serialNumber
        }
        ywkhService.validSerialNumber2G(param).then(function(success){
          if(success.respCode!="0"){
            var alertPopup=$ionicPopup.alert({
              title:'号码预占失败',
              template:""/*angular.toJson(success)*/,
              okText: '确定', // String (默认: 'OK')。OK按钮的文字。
              okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
            });
          }else{
            $scope.params.step3=1;
          }
        },function(error){
        });
      }
    }
//选中发展人时改变选中item颜色，同时给params传递选中的值
    $scope.selectfzr = function (index, item) {
      $scope.fzrselect = index;
      $scope.params.Developer= item;
      $scope.params.step3_2=1;
    };

    $scope.queryDevelopList = function (action,page) {
     $scope.params.step3_2=0;
     $scope.action=action;
    var param={};
      if(sysCode()=="CBS"){
        param={
          "sysCode":sysCode(),
          "provinceId": 71, // 省份代码，必选
          "channelCode":"",  // 渠道编码，可选
          "channelName":"",  // 渠道名称，可选
          "developName":!$scope.params.queryfzr?"":$scope.params.queryfzr,  // 发展人名称，可选
          "developSerialNumber":"", // 发展人手机号码，可选
          "developCode":"",  // 发展人编码，可选
          "RowCount":20, // 每页条数，必选,
          "Page":page// 第几页，必选
        };
      }else{
        param={
          "sysCode":sysCode(),
          "provinceId": 71, // 省份代码，必选
          "channelCode":$localstorage.get("DEPART_ID"),  // 渠道编码，可选
          "channelName":"",  // 渠道名称，可选
          "developName":!$scope.params.queryfzr?"":$scope.params.queryfzr, // 发展人名称，可选
          "developSerialNumber":"", // 发展人手机号码，可选
          "developCode":"",  // 发展人编码，可选
          "RowCount":20, // 每页条数，必选,
          "Page":page// 第几页，必选
        };
      }
    ywkhService.queryDevelopList(param).then(function (success) {
      if($scope.action=='loadmore'){
        //console.log(param);
        $timeout(function(){
          $scope.$broadcast('scroll.infiniteScrollComplete');
        },1000);
        if(!success.data||success.data.length==1){
          $scope.params.DevelopmoreData=false;
        }else{
          $scope.params.DeveloperList=$scope.params.DeveloperList.concat(angular.fromJson(success.data));
          $scope.step3_2page++;
        }
      }else{
        $scope.params.DeveloperList=angular.fromJson(success.data);
        $scope.step3_2page=2;//因为每次刷新后页面会重置为1，然后再去调用上拉加载的方法，才会拼接第二页的数据，不然就会拼接第一页数据，重复显示。
        $scope.$broadcast('scroll.refreshComplete');
      }

    }, function (error) {
    //console.log(error);
    });
   }

    $scope.doDevelopRefresh=function(){
      $scope.action='';
      $scope.params.step3_2=0;
      $scope.step3_2page=1;
      $scope.queryDevelopList('refresh',1);
    }
    $scope.doDevelopLoadMore=function(){
      $scope.queryDevelopList('loadmore',$scope.step3_2page);
    }
//=======================================step4==================================================
    $scope.createOrder=function(){
      var sex=null;
      if($scope.params.IdCard.sex=="男"){
        sex="1";
      }else{
        sex="0";
      }
      var strFromTo= new Array();
      strFromTo=$scope.params.IdCard.period.split("-");
      var ACTIVITY_ID="89000100";
      var ACTIVITY_TYPE="CFSF001";
      var ACTIVITY_NAME="存费送费合约存120元送240元(12个月)";
      var ACTIVITY_DETAIL="预存120元120元分12月返还赠送费用240元分12月到账";
      var PRODUCT_ELE_GROUP="[{'productId' : '89000100', 'packageId' : '51000106','elementName' : '预存120元120元分12月返还赠送费用240元分12月到账','elementId' : '20000348','startDate' : '2016-02-01 00:00:00','endDate' : '2017-01-31 23:59:59','elementTypeCode' : 'D'}]";
      var PRODUCT_GROUP="[{'productMode' : '50', 'productName' : '存费送费合约存120元送240元(12个月)','brandCode' : '-1','productid' : '89000100','productExplain' : '存费送费合约存120元送240元(12个月)','netTypeCode' : '-1','productTypeCode' : 'CFSF001','endDate' : '2017-01-31 23:59:59','startDate' : '2016-02-01 00:00:00'}]";
     if($scope.params.val_tclx=="4G") {//4G开户预提交参数
       var param = {
         "CUST_ID":$scope.params.CustList.custId,
         "CUST_TYPE":$scope.params.CustList.custType,
         "ACTIVITY_NAME": ""/*ACTIVITY_NAME*/,
         "DEVELOPER_NAME": $scope.params.Developer.developName,
         "CHANNEL_NAME": $scope.params.Developer.channelName,
         "prodType": $scope.params.val_tclx,
         "PRODUCT_ELE_GROUP": ""/*PRODUCT_ELE_GROUP*/,
         "ACTIVITY_DETAIL": ""/*ACTIVITY_DETAIL*/,
         "PSPT_START_DATE": strFromTo[0],
         "ACTIVITY_TYPE": ""/*ACTIVITY_TYPE*/,
         "feemode": $scope.params.val_tczf,
         "DEVELOPER_CODE": $scope.params.Developer.developCode,
         "PRODUCT_GROUP": ""/*PRODUCT_GROUP*/,
         "SN_INFO": {
           "simCardNo": "",
           "price": "0",
           "productId": $scope.params.PhoneNum.productId,
           "netTypeCode": $scope.params.PhoneNum.netTypeCode,
           "numberSrc": $scope.params.PhoneNum.numberSrc,
           "prestore": "0",
           "leaseLength": $scope.params.PhoneNum.leaseLength,
           "advancePay": $scope.params.PhoneNum.advancePay,
           "numThawPro": $scope.params.PhoneNum.numThawPro,
           "numberType": $scope.params.PhoneNum.numberType,
           "firstMonthAmount": $scope.params.PhoneNum.firstMonthAmount,
           "leasePropertyTag": $scope.params.PhoneNum.leasePropertyTag,
           "classId": $scope.params.PhoneNum.classId,
           "lowCost": $scope.params.PhoneNum.lowCost,
           "feeCodeFee": $scope.params.PhoneNum.feeCodeFee,
           "sn": $scope.params.PhoneNum.serialNumber,
           "endMonthAmount": $scope.params.PhoneNum.endMonthAmount
         },
         "LH_TYPE": "1",//靓号类型 默认1
         "PSPT_END_DATE": strFromTo[1]=="长期"?"2050-12-31":strFromTo[1],
         "YC_TYPE": "0",//预存档次，默认0
         "CUST_NAME": $scope.params.IdCard.name,
         "IS_JOINACTIVITY": "0",//是否参加活动
         "PSPT_ORGAN": $scope.params.IdCard.authority,
         "BRAND_CODE": $scope.params.Product.BRAND_CODE,
         "ORDER_SOURCE": "03",//app是03,订单来源
         "PSPT_TYPE_CODE": "1",
         "PRODUCT_ID": $scope.params.Product.PRODUCT_ID,
         "PRODUCT_NAME": $scope.params.Product.PRODUCT_NAME,
         "SERIAL_NUMBER": $scope.params.PhoneNum.serialNumber,
         "PSPT_TYPE_NAME": "身份证18位",
         "CREATE_STAFF_ID": "",
         "ACTIVITY_ID": ""/*ACTIVITY_ID*/,
         "CONTACT_PHONE": $scope.params.ConTel,
         "PSPT_ID": $scope.params.IdCard.cardNo,
         "CONTACT_ADDRESS": $scope.params.IdCard.address,
         "SEX": sex,
         "CONTACT_PERSON": $scope.params.IdCard.name,
         "BIRTHDAY": $scope.params.IdCard.birth,
         "ORDER_TYPE": "10",
         "CARD_TYPE": "01",
         "PSPT_ADDR": $scope.params.IdCard.address,
         "PRODUCT_INFO": {
           "productMode": $scope.params.Product.PRODUCT_MODE,
           "productname": $scope.params.Product.PRODUCT_NAME,
           "syscode": $scope.params.val_tclx,
           "mustactivity": $scope.params.Product.MUST_ACTIVITY,
           "subType": !$scope.params.Product.SUB_TYPE ? "" : $scope.params.Product.SUB_TYPE,
           "brandcode": $scope.params.Product.BRAND_CODE,
           "price": $scope.params.Product.PRODUCT_PRICE.toString(),
           "traffic": $scope.params.Product.PRODUCT_TRAFFIC.toString(),
           "message": $scope.params.Product.PRODUCT_MESSAGE.toString(),
           "eProductId": !$scope.params.Product.E_PRODUCT_ID ? "" : $scope.params.Product.E_PRODUCT_ID,
           "call": $scope.params.Product.PRODUCT_CALL.toString(),
           "productId": $scope.params.Product.PRODUCT_ID.toString(),
           "productExplain": $scope.params.Product.PRODUCT_EXPLAIN,
           "endDate": $scope.params.Product.END_DATE,
           //"endDate":"2016-05-05 18:13",
           "nettypecode": $scope.params.Product.NET_TYPE_CODE,
           "producttypecode": $scope.params.Product.PRODUCT_TYPE_CODE,
           //"startDate":"2016-04-05 18:13"
           "startDate": $scope.params.Product.START_DATE
         },
         "CHANNEL_CODE": $scope.params.Developer.channelCode,
         "isJoinActivity": "0",//是否存在活动
         "SYS_CODE": sysCode(),
         "NATION": $scope.params.IdCard.ethnicity,
         "FEE_MODE": $scope.params.val_tczf
       }
     }
      else if($scope.params.val_tclx=="2G"){
       var param={//2G开户预提交参数
         "developSerialNumber":$scope.params.Developer.developSerialNumber,
         "SN_INFO":{
           "price" :"0",
           "sn" : $scope.params.PhoneNum.serialNumber,
           "serialnumber" : $scope.params.PhoneNum.serialNumber,
           "prestore" : "0"
         },
         "feemode": $scope.params.val_tczf,
         "CHANNEL_NAME":$scope.params.Developer.channelName,
         "DEVELOPER_NAME":$scope.params.Developer.developName,
         "prodType": $scope.params.val_tclx,
         "PSPT_START_DATE":strFromTo[0],
         "DEVELOPER_CODE":$scope.params.Developer.developCode,
         "PSPT_END_DATE":strFromTo[1]=="长期"?"2050-12-31":strFromTo[1],
         "CUST_NAME":$scope.params.IdCard.name,
         "PSPT_ORGAN": $scope.params.IdCard.authority,
         "BRAND_CODE":$scope.params.Product.BRAND_CODE,
         "SIM_CARD_NO":!$scope.params.BarSimCard.text?"":$scope.params.BarSimCard.text,
         "PSPT_TYPE_CODE":"1",
         "ORDER_TYPE":"10",
         "ORDER_SOURCE": "03",//app是03,订单来源
         "PRODUCT_ID":$scope.params.Product.PRODUCT_ID,
         "PRODUCT_NAME":$scope.params.Product.PRODUCT_NAME,
         "SERIAL_NUMBER":$scope.params.PhoneNum.serialNumber,
         "phoneRadio":$scope.params.PhoneNum.serialNumber,
         "PSPT_TYPE_NAME":"身份证18位",
         "pagename":"open.PreOpen",
         "CONTACT_PHONE":$scope.params.ConTel,
         "PSPT_ID":$scope.params.IdCard.cardNo,
         "CONTACT_ADDRESS":$scope.params.IdCard.address,
         "SEX":sex,
         "CONTACT_PERSON":$scope.params.IdCard.name,
         "BIRTHDAY":$scope.params.IdCard.birth,
         "CARD_TYPE":$scope.params.val_kplb=="白卡"?"01":"02",//01是白卡，02是成卡
         "PSPT_ADDR":$scope.params.IdCard.address,
         "CHANNEL_CODE":$scope.params.Developer.channelCode,
         "SYS_CODE":sysCode(),
         "NATION":$scope.params.IdCard.ethnicity,
         "eventname":"creteOpenOrder",
       }

     }
      ywkhService.do_createOrder_req(param).then(
        function(success){
          var alertPopup=$ionicPopup.alert({
            title:'提交订单',
            template:"提交订单成功，请去订单中查询！"/*angular.toJson(success)*/,
            okText: '确定', // String (默认: 'OK')。OK按钮的文字。
            okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
          });
          var orderId=success.data;
          var queryparam=ddcxService.getParams();
          queryparam.orderQueryParams.orderId=orderId;
          if("CBS"==sysCode()){
            queryparam.CustList=$scope.params.CustList;
          }

          $state.go("ddcxdetails");
      },function(error){
          var alertPopup=$ionicPopup.alert({
            title:'提交订单失败',
            template:angular.toJson(error),
            okText: '确定', // String (默认: 'OK')。OK按钮的文字。
            okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
          });
      });
    }

//==========================全局调用方法==================================================
    function sysCode(){
      var sysCode = null;
      if ($scope.params.val_tclx == '2G') {
        sysCode = 'BSS';
      } else if ($scope.params.val_tclx == '3G') {
        sysCode = "ESS";
      }
      else {
        sysCode = "CBS";
      }
      return sysCode;
    }

    //手指触碰改变popover样式
    $scope.color=function(index){
      $scope.colorindex=index;
    }


  }]);
